package com.it00zyq.admin.controller;

import com.it00zyq.admin.param.ArticleParam;
import com.it00zyq.admin.service.ArticleService;
import com.it00zyq.common.param.ListParam;
import com.it00zyq.common.utils.R;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @Author zyq
 * @Date 2022/4/29 13:04
 * @Description TODO
 * @Version 1.0
 **/
@RestController
@RequestMapping("/api/article")
@RequiredArgsConstructor
public class ArticleController {

    private final ArticleService service;

    /**
     * 发布文章
     */
    @PostMapping
    public R publish(@RequestBody @Valid ArticleParam param, @RequestHeader("token") String token) {
        service.publish(param, token);
        return R.ok();
    }

    /**
     * 修改文章内容
     */
    @PutMapping
    public R modify(@RequestBody @Valid ArticleParam param) {
        service.modify(param);
        return R.ok();
    }

    /**
     * 获取文章详情
     */
    @GetMapping("/detail/{id}")
    public R detail(@PathVariable("id") Integer id) {
        return R.ok().data(service.detail(id));
    }

    /**
     * 获取文章列表
     */
    @GetMapping("/list")
    public R list(ListParam param) {
        return R.ok().data(service.list(param));
    }

    /**
     * 获取基本数据
     */
    @GetMapping("/base")
    public R base() {
        return R.ok().data(service.baseData());
    }

}
